﻿using Common;
using Common.EdgeBytes;
using MQXT.BLL;
using Oliving.CommonPC.Log;
using ScokTcpLib;
using ScokTcpLib.ScokTcpServer;
using SocketTool.Socket;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace SocketTool
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            EdgeLog.writeLog("button1_Click", "OK ");

            button1.Enabled = false;
            TcpipCjq.InitSocket();


        }

         

        private void button2_Click_1(object sender, EventArgs e)
        {
            int addr = 0;
            string result = "";
            TcpipJzq.Check_ZhuCe("addr:12345678;sim:14541358567;yb:001;gps:111.111111111.111111;ver:JZQ;over;", null, out result, 0, out addr);

            //  byte[] datashow = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0x03, 0x00, 0x00, 0x00, 0x03 };


            //                           00-00-00-00-00-06-78-03-00-67-00-02
            byte[] datashow = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x78, 0x03, 0x00, 0x67, 0x00, 0x02 };
            //                                                               从站地址        寄存器        长度
            int isSend = TcpipJzq.Check_ZhuCe(Encoding.UTF8.GetString(datashow, 0, datashow.Length), datashow, out result, 0, out addr);


            if (isSend == 2)
            {
                if (!string.IsNullOrEmpty(result))
                {
                    // 发送 result

                    byte[] bytTemp2 = BytesHelper.EdgeGetBytes(result);


                    string stringdata = BitConverter.ToString(bytTemp2, 0, bytTemp2.Length);


                    Console.WriteLine(stringdata);
                }

            }

        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            button1_Click(null, null);
            button3_Click(null, null);



            Thread thread = new Thread(() =>
            {
                while (true)
                {

                    try
                    {
                        string myPath = Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "log");
                        DelLog.Del(myPath);
                    }
                    catch { }

                    Thread.Sleep(2 * 60 * 60);
                }


            });
            thread.IsBackground = true;
            thread.Start();





        }

        private void button3_Click(object sender, EventArgs e)
        {

            button3.Enabled = false;
            TcpipJzq.InitSocket();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            EdgeDataAnalysis.Check_ZhuCe("addr:12345678;sim:15012345678;yb:120;gps:111.111111111.111111;ver:CJQ;counter:005;reg1:0100;reg2:0101;reg3:0102;reg4:0103;reg5:0104;reg6:0006;reg7:0007;reg8:0008;reg9:0009;reg10:0010;over;", "-1");
            EdgeDataAnalysis.Check_ZhuCe("addr:12345678;2312;1285;1288;1538;520;over;", "-1");

        }
    }
}
